<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui">
    <head>
        <p:resources />
    </head>
    <body>
        <ui:composition template="./../Template/generalTemplate.xhtml">
            <ui:define name="content">
                <h:form id="LineItem">    

                  

                    <p:panel  id="salesOrderLineItems"  header="Purchase Order LineItem" toggleable="true" >
                       <h:outputText value ="#{amendPurchaseOrderManagedBean.msg}" style="color:red;"/>
                       <br/><br/>
                        <p:dataTable  id ="lineItemList" dynamic="true" emptyMessage="No product selected" value="#{amendPurchaseOrderManagedBean.lineItemList}" var="o" paginator="true" rows="4">

                            <p:column>
                                <f:facet name="header">Product Name</f:facet>

                                #{o.product.productName}

                            </p:column> 

                            <p:column>
                                <f:facet name="header">Quantity</f:facet>

                                #{o.quantity}

                            </p:column>

                            <p:column>
                                <f:facet name="header">Delivery Date</f:facet>

                                <h:outputText value="#{o.deliveryDate}">
                                    <f:convertDateTime pattern ="dd/MM/yyyy"/>
                                </h:outputText>    

                            </p:column> 

                            <p:column>
                                <f:facet name="header">Delivery Location</f:facet>

                                #{o.deliveryLocation}

                            </p:column> 

                            <p:column>
                                <f:facet name="header">Unit Price</f:facet>   
                                #{o.price} 
                            </p:column>

                            <p:column>
                                <f:facet name="header">Cum Amount</f:facet>               
                                #{o.cumAmount}
                            </p:column>

                            <p:column>
                                <f:facet name="header">Edit</f:facet>
                                <h:commandLink value =" Delete"  action="#{amendPurchaseOrderManagedBean.deleteLineItem(o)}"/>
                            </p:column>        
                        </p:dataTable>
                        </p:panel>
                      </h:form> 
                 <h:form>       
                     <p:panel>
                        <h:panelGrid columns ="3">
                            <h:outputText value="ChooseProduct: "/>
                            <h:selectOneMenu id="productType" value="#{amendPurchaseOrderManagedBean.productId}">  
                                <f:selectItems value="#{amendPurchaseOrderManagedBean.productList}" />
                            </h:selectOneMenu>

                            <br/>
                            <h:outputText value = "Quantity"/>
                            <h:inputText  value="#{amendPurchaseOrderManagedBean.lineItem.quantity}" required="true"/>
                            <br/>

                            <h:outputText value = "Delivery Date (dd/mm/yyyy)"/>
                            <h:inputText  value="#{amendPurchaseOrderManagedBean.lineItem.deliveryDate}" required="true">
                                <f:convertDateTime pattern ="dd/MM/yyyy"/>
                            </h:inputText>

                            <br/>

                            <h:outputText value = "Delivery Location"/>
                            <h:inputText  value="#{amendPurchaseOrderManagedBean.lineItem.deliveryLocation}" required="true"/>

                            <br/>

                            <h:outputText value = "Unit Price"/>
                            <h:outputText id="unitPrice" value="#{amendPurchaseOrderManagedBean.lineItem.price}"/>


                            <br/>

                            <h:outputText value = "Cum Amount"/>
                            <h:outputText  id="cumAmount" value="#{amendPurchaseOrderManagedBean.lineItem.cumAmount}" />
                            <p:poll interval="2"   
                                    actionListener="#{amendPurchaseOrderManagedBean.calculateCumAmount}" update="unitPrice cumAmount" />           
                            <br/>
                            <p:commandButton value="Add" ajax ="false" update="lineItem" actionListener ="#{amendPurchaseOrderManagedBean.addLineItem}"/>


                        </h:panelGrid>   
                    </p:panel>

                </h:form>
                <h:form >

                    <p:notificationBar position="bottom" effect="slide" widgetVar="bottomBar" styleClass="bottom" >  
                        <f:facet name="close">  
                            <p:graphicImage value="/images/closebar.png" />  
                        </f:facet>  
                        <h:panelGroup id="bottomPanel" style="margin-right:200px;">  
                            <!--<p:messages />-->  
                            <h:outputText value="ERROR: #{amendPurchaseOrderManagedBean.errorMessage}"  />  
                        </h:panelGroup>  
                    </p:notificationBar>


                    <p:commandButton  update="bottomPanel"  oncomplete="bottomBar.show();"  value="Save"  actionListener="#{amendPurchaseOrderManagedBean.amendPurchaseOrder}" />
                </h:form>


            </ui:define>

        </ui:composition>

    </body>
</html>
